package net.fornwall.eclipsecoder.actions;

import org.eclipse.core.resources.IFile;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.ui.IObjectActionDelegate;
import org.eclipse.ui.IWorkbenchPart;

public class GenerateSourceAction implements IObjectActionDelegate {

	IFile selectedFile;

	IWorkbenchPart targetPart;

	public void run(IAction action) {
		System.out.println("GenerateSourceAction.run()");
		try {
			// ObjectInputStream objectInput = new
			// ObjectInputStream(selectedFile.getContents());
			// Language language = (Language) objectInput.readObject();
			// ProblemComponentModel problem = (ProblemComponentModel)
			// objectInput.readObject();
			// Renderer renderer = (Renderer) objectInput.readObject();
			// objectInput.close();
			//
			// LanguageSupport languageSupport = null;
			// System.out.println("SRM FILE FOR PROBLEM: " +
			// languageSupport.getSolutionClassName());
			// System.out.println("#######\n" +
			// languageSupport.getInitialSource());

		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	@SuppressWarnings("unchecked")
	public void selectionChanged(IAction action, ISelection selection) {
		StructuredSelection fileSelection = (StructuredSelection) selection;
		if (fileSelection.getFirstElement() instanceof IFile) {
			selectedFile = (IFile) fileSelection.getFirstElement();
			System.out.println("SELECTED FILE: " + selectedFile.getLocation());
		}
	}

	public void setActivePart(IAction action, IWorkbenchPart targetPart) {
		System.out.println("GenerateSourceAction.setActivePart()");
		this.targetPart = targetPart;
	}

}
